var app = getApp();

Page({
    data: {
        navH: 0,
        showSnatchShade: !1,
        showTimeBox: !1,
        showFailureShade: !1,
        showWinureShade: !1,
        goodsList: [],
        total: 0,
        share_uid: 0,
        second: 0,
        millisecond: "00",
        setInter: "",
        is_win: 1,
        win_id: 0,
        win_title: "",
        win_img: "",
        hot_page: 1,
        hotGoodsList: !1,
        from_uid: 0
    },
    getSpeedLootingInfo: function() {
        var a, t = this;
        app.globalData.userInfo && t.data.share_uid && (a = {
            share_uid: t.data.share_uid
        }), app.util.request({
            url: "entry/wxapp/getSpeedLootingInfo",
            data: a,
            success: function(a) {
                app.globalData.userInfo && t.data.share_uid && (t.data.share_uid = 0, app.globalData.setting = a.data.data.setting), 
                console.log(a.data.data), t.setData({
                    goodsList: a.data.data.list,
                    total: a.data.data.total
                });
            }
        });
    },
    toWinningPage: function() {
        wx.navigateTo({
            url: "./winning-record"
        });
    },
    getHotGoods: function() {
        var t = this;
        t.data.hot_loading || (t.data.hot_loading = !0, app.util.request({
            url: "entry/wxapp/getHotGoods",
            showLoading: !1,
            data: {
                page: t.data.hot_page,
                sort_type: 0
            },
            success: function(a) {
                console.log(a), a.data.data.length < 1 || (t.data.hotGoodsList = 1 == t.data.hot_page ? a.data.data : t.data.hotGoodsList.concat(a.data.data), 
                t.setData({
                    hotGoodsList: t.data.hotGoodsList
                }), t.data.hot_page++);
            },
            complete: function() {
                t.data.hot_loading = !1;
            }
        }));
    },
    showInfo: function() {
        app.showInfo(this, app.globalData.setting.speedlooting_rule_intro);
    },
    hideInfo: function() {
        app.hideInfo(this);
    },
    toHotMore: function() {
        wx.navigateTo({
            url: "../region/region"
        });
    },
    onLoad: function(a) {
        var t = a.from_uid || 0;
        this.setData({
            navH: app.globalData.navHeight,
            from_uid: t,
            share_uid: a.share_uid
        }), this.getSpeedLootingInfo(), this.getHotGoods();
    },
    loginAfter: function(a) {
        app.loginAfter(a);
    },
    loginCancel: function() {
        app.loginCancel();
    },
    navBack: function() {
        0 < this.data.from_uid ? wx.switchTab({
            url: "../index/index"
        }) : wx.navigateBack();
    },
    toIndex: function() {
        wx.switchTab({
            url: "../index/index"
        });
    },
    openSnatchShade: function() {
        app.globalData.userInfo ? 0 < this.data.total ? (this.setData({
            showTimeBox: !0,
            endK: !0
        }), this.setInterval()) : this.setData({
            showSnatchShade: !0
        }) : app.checkLogin();
    },
    toOtherGoods: function(a) {
        var t = a.currentTarget.dataset.goods_id;
        void 0 !== a.currentTarget.dataset.goods_sign && (t += "&goods_sign=" + a.currentTarget.dataset.goods_sign), 
        wx.navigateTo({
            url: "../goods/goods?goods_id=" + t
        });
    },
    setInterval: function(a) {
        function t() {
            return a.apply(this, arguments);
        }
        return t.toString = function() {
            return a.toString();
        }, t;
    }(function() {
        var a = this, t = a.data.millisecond, o = a.data.second;
        a.data.setInter = setInterval(function() {
            100 <= (t += 2) && (t = 0, o++, a.setData({
                second: o
            })), t < 10 ? a.setData({
                millisecond: "0" + t
            }) : a.setData({
                millisecond: t
            });
        }, 20);
    }),
    onTestForEnd: function() {
        var a = this;
        clearInterval(a.data.setInter), a.data.total <= 0 || (a.setData({
            endK: !1
        }), a.goTreasureResult());
    },
    goTreasureResult: function() {
        wx.showLoading({
            title: "开奖中",
            mask: !0
        });
        var t = this, a = t.data.goodsList;
        console.log(t.data.second + "***" + t.data.millisecond);
        for (var o = 0; o < a.length; o++) if (t.data.second == a[o].info[0] && t.data.millisecond == a[o].info[1]) {
            t.setData({
                is_win: 2,
                win_id: a[o].id,
                win_img: a[o].img,
                win_title: a[o].title
            });
            break;
        }
        app.util.request({
            url: "entry/wxapp/goProveSpeedResult",
            showLoading: !1,
            success: function(a) {
                "ok" == a.data.message && (a = t.data.total - 1, t.setData({
                    total: a
                })), setTimeout(function() {
                    t.setData({
                        showTimeBox: !1,
                        millisecond: "00",
                        second: 0
                    }), 1 == t.data.is_win ? t.setData({
                        showFailureShade: !0
                    }) : 2 == t.data.is_win && t.setData({
                        showWinureShade: !0
                    });
                }, 1e3);
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    chooseWinureShade: function() {
        this.setData({
            showWinureShade: !1,
            is_win: 1
        });
    },
    goAddAdress: function() {
        var t = this, a = t.data.address[0];
        app.util.request({
            url: "entry/wxapp/goAddSlAddress",
            data: {
                is_win: t.data.is_win,
                win_id: t.data.win_id,
                win_img: t.data.win_img,
                win_title: t.data.win_title,
                name: a.userName,
                province: a.provinceName,
                city: a.cityName,
                county: a.countyName,
                detail: a.detailInfo,
                tel: a.tel
            },
            success: function(a) {
                console.log(a.data.data), t.setData({
                    is_win: 1
                }), "ok" == a.data.message && (t.setData({
                    showWinureShade: !1
                }), t.toWinningPage());
            }
        });
    },
    onGetaddress: function() {
        var t = this;
        wx.chooseAddress({
            success: function(a) {
                a = [ {
                    userName: a.userName,
                    tel: a.telNumber,
                    provinceName: a.provinceName,
                    cityName: a.cityName,
                    countyName: a.countyName,
                    detailInfo: a.detailInfo
                } ];
                t.setData({
                    address: a
                }), t.goAddAdress(), console.log(t.data.address);
            }
        });
    },
    addAddress: function() {
        wx.navigateTo({
            url: "./share-treasure?uid=" + app.globalData.userInfo.uid
        });
    },
    chooseSnatchShade: function() {
        this.setData({
            showSnatchShade: !1
        });
    },
    chooseFailureShade: function() {
        this.setData({
            showFailureShade: !1
        });
    },
    toShareTreasure: function() {
        app.globalData.userInfo ? wx.navigateTo({
            url: "./share-treasure?uid=" + app.globalData.userInfo.uid
        }) : app.checkLogin();
    },
    toGoodsPage: function(a) {
        console.log(a);
        var t = a.currentTarget.dataset.goods_id, o = a.currentTarget.dataset.goods_sign;
        void 0 !== a.currentTarget.dataset.source ? (a = "&source=" + a.currentTarget.dataset.source, 
        o && (a += "&goods_sign=" + o), wx.navigateTo({
            url: "../goods/goods?goods_id=" + t + a
        })) : (o && (t += "&goods_sign=" + o), wx.navigateTo({
            url: "../goods/goods?goods_id=" + t
        }));
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        clearInterval(this.data.setInter);
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});